﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeatherNet.yahoo;

namespace WeatherNet
{
    public class WeatherResult
    {
        public string City { get; set; }

        public string Country { get; set; }

        public string Region { get; set; }

        public int Code { get; set; }

        public string Date { get; set; }

        public int Temperature { get; set; }

        public string Summary { get; set; }

        public IEnumerable<WeatherForecast> Forecast { get; set; }


        public WeatherResult()
        { }

        internal WeatherResult(YQLWeatherQuery.location location, YQLWeatherQuery.condition condition, YQLWeatherQuery.forecast[] forecast)
        {
            if (location != null)
            {
                this.City = location.city;
                this.Country = location.country;
                this.Region = location.region;
            }

            if (condition != null)
            {
                this.Code = condition.code;
                this.Date = condition.date;
                this.Summary = condition.text;
                this.Temperature = condition.temp;
            }

            if (forecast != null)
            {
                var forecastList = new List<WeatherForecast>();

                foreach (var fc in forecast)
                {
                    forecastList.Add(new WeatherForecast(fc.code, fc.date, fc.day, fc.high, fc.low, fc.text));
                }
                this.Forecast = forecastList;
            }
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}, {2}, {3}, {4}, {5}, {6}, [{7}]", this.City, this.Country, this.Region,
                this.Code, this.Date, this.Summary,
                this.Temperature, string.Join("--", this.Forecast));
        }
    }


    public class WeatherForecast
    {
        public WeatherForecast(int code, string date, string day, int high, int low, string summary)
        {
            this.Code = code;
            this.Date = date;
            this.Day = day;
            this.High = high;
            this.Low = low;
            this.Summary = summary;
        }

        public int Code { get; set; }

        public string Date { get; set; }

        public string Day { get; set; }

        public int High { get; set; }

        public int Low { get; set; }

        public string Summary { get; set; }

        public override string ToString()
        {
            return string.Format("Forecast: {0}, {1}, {2}, {3}, {4}, {5}",
                this.Code, this.Date, this.Day, this.High, this.Low, this.Summary);
        }
    }

}
